#!/bin/bash

commit_hash=$(git rev-parse HEAD)
curPwd=$(pwd)
echo "最新提交号是: $commit_hash"
echo "最新提交号是: $curPwd"

appName=analysis

checkK8s() {
  cd $3
  cd ../k8s/
  cd service/$1
  sed -i "s/harbor\.qtmerla\.com:30566\/merla\/$1:.*/harbor.qtmerla.com:30566\/merla\/$1:$2/" "$1.yaml"
  cd $3
}

clearK8s() {
  cd $1
  cd ../k8s/
  git checkout .
  git pull
}

commitK8s() {
  cd $1
  cd ../k8s/
  git add .
  git commit -m "fix $2"
  git push
}

build() {
  cd $3

  docker build -f ./docker/dev/Dockerfile ./ -t harbor.qtmerla.com:30566/merla/$1:$2
  docker push harbor.qtmerla.com:30566/merla/$1:$2
}

clearK8s $curPwd
build $appName $commit_hash $curPwd
checkK8s $appName $commit_hash $curPwd

commitK8s $curPwd $commit_hash